package my.mall.front.api.controller

import my.mall.common.pojo.CommonResp
import my.mall.common.pojo.PageParam
import my.mall.common.pojo.PageResp
import my.mall.common.util.RespUtils.success
import my.mall.front.api.service.GoodsService
import my.mall.front.api.pojo.goods.GoodsDetail
import my.mall.front.api.pojo.goods.GoodsItem
import my.mall.front.api.pojo.goods.SkuDetail
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/goods")
class GoodsController(
    private val goodsService: GoodsService
) {

    @GetMapping("/list")
    fun goodsList(pageParam: PageParam): CommonResp<PageResp<GoodsItem>> {
        return goodsService.getGoodsList(pageParam)
    }

    @GetMapping("/detail")
    fun getGoodsDetail(@RequestParam("goodsId") goodsId: Long?): CommonResp<GoodsDetail> {
        return success(goodsService.getGoodsDetail(goodsId))
    }

    @GetMapping("/sku/detail")
    fun getSkuDetail(
        @RequestParam("goodsId") goodsId: Long?,
        @RequestParam("skuId") skuId: Long?
    ): CommonResp<SkuDetail?> {
        return success(goodsService.getSkuDetail(goodsId, skuId))
    }
}
